
require "game/ui/form/blacksmith/UICreationGate"

-- 沙漠祭坛
function initCreationGate2(self)
    self.item:removeAllChildren();

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- boss层中
            local dungeonId = DungeonM.getDungeonId();
            local layer     = DungeonM.currentLayer();
            if DungeonBossM.isBossLayer(dungeonId, layer) and not DungeonM.isAllMonsterDead() then
                alert(getLocStr("pick_up_instance_target_fail"));
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 音效
            AudioM.playFx("workshop_open_ui");

            local pos = self.gridData:getPos();

            -- 打开工坊界面
            if UIMgr.getCurrentScene():isOpen("UICreationGate") then
                UIMgr.getCurrentScene():removeFormByName("UICreationGate");
            end
            local uiForm = UICreationGate.create(pos, "normal_submit");
            UIMgr.getCurrentScene():addForm(uiForm);
        end
    end

    -- 工坊图标
    -- local class = self.gridData.classify;
    -- local data = DemonStatueM.queryStatue(class, 1);
    -- local icon = data["icon"] or "demon_statue";
    local icon = BuildingBonusM.queryBuildingView(self.gridData.class, "icon");
    icon = getLevelItemIconPath(icon);

    self.icon = ccui.ImageView:create(icon);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end
